package yao.spider.jsoup.vobao;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

import com.google.common.collect.Range;

import yao.spider.jsoup.vobao.bean.Question;

public class MainProcess {
	
	private static final ExecutorService producerPool = Executors.newFixedThreadPool(10);
	private static final ExecutorService consumerPool = Executors.newFixedThreadPool(15);
	
	public static void main(String[] args) {

		BlockingQueue<Question> urlQueue = new LinkedBlockingQueue<>(200);
		// 生产者
		TagEnum tagEnum = TagEnum.YENEI_ZHIYE;
		for(int i=1; i <= tagEnum.getLastPageNum(); i++) {
			Range<Integer> range = Range.closed(i, i);
			PageUrlCrawler pageUrlCrawler = new PageUrlCrawler(urlQueue, range, tagEnum);			
			producerPool.execute(pageUrlCrawler);			
		}
		//消费者
		for(int i=0; i<15; i++) {
			QuestionCrawler questionCrawler = new QuestionCrawler(urlQueue, ResultHandler.getInstance());
			consumerPool.execute(questionCrawler);
		}

	}

}
